/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;

import com.cashmate.hibernate.dao.AreaDAO;
import com.cashmate.hibernate.pojo.Areas;
import com.cashmate.hibernate.pojo.Branches;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Sarah
 */
public class GetAreas extends ActionSupport {

    private static Logger logger = Logger.getLogger(GetAreas.class);
    private AreaDAO ar = (AreaDAO) ServletActionContext.getServletContext().getAttribute("areaDAO");
    private List<Areas> areas;

    public List<Areas> getAreas() {
        return areas;
    }

    @Action(value = "/get-areascoll", results = {
        @Result(name = "success", location = "../../loancollection.jsp")
    })
    public String getAreasList() {
        try {
            Branches b = (Branches) ServletActionContext.getRequest().getSession().getAttribute("branch");
            areas = ar.getAreasPerBranch(b.getBranchid());
//            System.out.println("AREAS:"+areas);
            return SUCCESS;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }
}
